package com.ciwong.epaper.modules.me.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ciwong.ciwongwrite.utils.CWUtils;
import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EpaperConstant;
import com.ciwong.epaper.modules.epaper.bean.ModuleInfo;
import com.ciwong.epaper.modules.me.bean.MyWork;
import com.ciwong.epaper.modules.me.bean.RequirementContent;
import com.ciwong.epaper.modules.me.bean.WorkContents;
import com.ciwong.epaper.util.DisplayUtils;
import com.ciwong.epaper.util.PopWindowUtil;
import com.ciwong.epaper.widget.HomeWorkHintDialog;
import com.ciwong.libs.utils.CWLog;
import com.ciwong.mobilelib.utils.ToastUtil;
import com.google.gson.Gson;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 我的作业适配器
 */
public class HomeWorkAdapter extends BaseExpandableListAdapter {

    //是否删除 1:已删除  0:未删除

    private final int HOMEWORK_STATU_NORMAL = 0;
    private final int HOMEWORK_STATU_DELETE = 1;
    /**
     * 上下文
     */
    private Context mContext;

    private Activity mActivity;

    private List<MyWork> myWorks;

    private boolean isClassWork;

    /**
     * 作业类型 0做作业，1订正错题
     */
    private int workType = 0;
    private int TEXT_SIZE_ZH = 14;
    private int TEXT_SIZE_EN = 18;

    /**
     * @param activity
     * @param myWorks     作业
     * @param workType    作业类型 0做作业，1订正错题
     * @param isClassWork 是否是课堂作业
     */
    public HomeWorkAdapter(Activity activity, List<MyWork> myWorks, int workType, boolean isClassWork) {
        this.mContext = activity;
        this.mActivity = activity;
        this.myWorks = myWorks;
        this.workType = workType;
        this.isClassWork = isClassWork;

    }

    @Override
    public int getGroupCount() {
        return myWorks.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        if (groupPosition < myWorks.size()) {
            return myWorks.get(groupPosition).getWorkContents().size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getGroup(int groupPosition) {
        return myWorks.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return myWorks.get(groupPosition).getWorkContents()
                .get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return myWorks.size();
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return myWorks.get(groupPosition).getWorkContents().size();
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        GroupViewHolder groupViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_home_work_group_layout, null);
            groupViewHolder = new GroupViewHolder();
            groupViewHolder.item_my_group_parent_view = convertView.findViewById(R.id.item_my_group_parent_view);
            groupViewHolder.iv_my_work_status_start = convertView.findViewById(R.id.iv_my_work_status_start);
            groupViewHolder.iv_my_work_status_finish = convertView.findViewById(R.id.iv_my_work_status_finish);
            groupViewHolder.mTimeTv = convertView.findViewById(R.id.item_my_group_time_tv);
            groupViewHolder.iv_my_group_msg = convertView.findViewById(R.id.iv_my_group_msg);
            convertView.setTag(groupViewHolder);
        } else {
            groupViewHolder = (GroupViewHolder) convertView.getTag();
        }
        setGroupView(groupPosition, groupViewHolder);
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        ChildViewHolder childViewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_home_work_child_layout, null);
            childViewHolder = new ChildViewHolder();
            childViewHolder.tv_work_child_name = convertView.findViewById(R.id.tv_work_child_name);
            childViewHolder.child_diveder = convertView.findViewById(R.id.child_diveder);
            //跟读次数
            childViewHolder.tv_hint_msg = convertView.findViewById(R.id.tv_hint_msg);
            childViewHolder.tv_reRead = convertView.findViewById(R.id.tv_reRead);
            childViewHolder.tv_work_description = convertView.findViewById(R.id.tv_work_description);
            childViewHolder.tv_score_obtain = convertView.findViewById(R.id.tv_score_obtain);

            childViewHolder.iv_work_type_icon = convertView.findViewById(R.id.iv_work_type_icon);
            childViewHolder.iv_work_type_kaoshi_icon = convertView.findViewById(R.id.iv_work_type_kaoshi_icon);
            childViewHolder.tv_comment = convertView.findViewById(R.id.tv_comment);

            childViewHolder.tv_total_score = convertView.findViewById(R.id.tv_total_score);

            childViewHolder.word_repeat_area = convertView.findViewById(R.id.word_repeat_area);
            childViewHolder.work_btn_area = convertView.findViewById(R.id.work_btn_area);
            childViewHolder.ll_tv_hint_msg = convertView.findViewById(R.id.ll_tv_hint_msg);
            childViewHolder.work_tips_lay = convertView.findViewById(R.id.work_tips_lay);
            childViewHolder.tv_total_finish_count = convertView.findViewById(R.id.tv_total_finish_count);
            convertView.setTag(childViewHolder);
        } else {
            childViewHolder = (ChildViewHolder) convertView.getTag();
        }
        setChildView(groupPosition, childPosition, childViewHolder);
        return convertView;
    }

    /**
     * 设置父标题
     *
     * @param groupPosition
     * @param groupViewHolder
     */
    private void setGroupView(final int groupPosition,
                              final GroupViewHolder groupViewHolder) {
        try {
            final MyWork myWork = myWorks.get(groupPosition);
            if (myWork.getIsDel() == HOMEWORK_STATU_DELETE) {//作业已删除
                groupViewHolder.item_my_group_parent_view.setVisibility(View.GONE);
            } else {
                groupViewHolder.item_my_group_parent_view.setVisibility(View.VISIBLE);
                final String workName = mContext.getResources().getString(R.string.str_homework_name) + "  " + myWork.getWorkName();
                SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm");
                final String startMountAndDay = CWUtils.formatDate5two(myWork.getSendDate() * 1000);
                final String startHourtime = formatter2.format(myWork.getSendDate() * 1000);
                String startWeekDate = CWUtils.formatDateToWeek2(myWork.getSendDate() * 1000);
                final String startTime = mContext.getResources().getString(R.string.str_start_dead_line) + "  " + startMountAndDay + " (" + startWeekDate + ") " + startHourtime;
                final String endMountAndDay = CWUtils.formatDate5two(myWork.getEffectiveDate() * 1000);
                final String endHourtime = formatter2.format(myWork.getEffectiveDate() * 1000);
                String endWeekDate = CWUtils.formatDateToWeek2(myWork.getEffectiveDate() * 1000);
                List<WorkContents> workContents = myWork.getWorkContents();
                String endTimeTip = mContext.getResources().getString(R.string.str_dead_line);
                if (workContents.size() > 0 && workContents.get(0).getExamMode() == 2) {
                    endTimeTip = mContext.getResources().getString(R.string.str_date_line);
                }
                final String endTime = endTimeTip + "  " + endMountAndDay + " (" + endWeekDate + ") " + endHourtime;
                String autoRefuseModeStr = "";
                String seeWorkModeStr = "";
                String submitModeStr = "";
                if (myWork.getAutoRefuseMode() == 1) {
                    autoRefuseModeStr = "  退" + myWork.getAutoRefusePercent() + "%  最多退" + myWork.getAutoRefuseNum() + "次";

                }
                if (myWork.getSeeWorkMode() == 0) {
                    seeWorkModeStr = "  详情可查看";
                } else if (myWork.getSeeWorkMode() == 1) {
                    seeWorkModeStr = "  截止后可看";
                } else {
                    seeWorkModeStr = "  详情不可看";
                }
                if (myWork.getSubmitMode() == 0) {
                    submitModeStr = "  可补交";
                } else {
                    submitModeStr = "  不可补交";
                }
                final String workMessage = mContext.getResources().getString(R.string.str_homework_message) + "  " + myWork.getWorkMessage();
                final String workOption = mContext.getResources().getString(R.string.str_homework_option) + seeWorkModeStr + submitModeStr + autoRefuseModeStr;
                if (myWork.getEffectiveDate() > myWork.getNowDate()) {
                    //作业未结束
                    groupViewHolder.iv_my_work_status_start.setVisibility(View.VISIBLE);
                    groupViewHolder.iv_my_work_status_finish.setVisibility(View.GONE);
                    final String workTime = CWUtils.getWorkStopTime(myWork.getEffectiveDate() - myWork.getNowDate());
                    groupViewHolder.mTimeTv.setText("进行中-" + workTime + "后截止");
                    groupViewHolder.mTimeTv.setTextColor(mContext.getResources().getColor(R.color.color_light_green));
                    groupViewHolder.item_my_group_parent_view.setBackgroundColor(mContext.getResources().getColor(R.color.work_status_start));
                } else {
                    //作业已经结束
                    groupViewHolder.iv_my_work_status_start.setVisibility(View.GONE);
                    groupViewHolder.iv_my_work_status_finish.setVisibility(View.VISIBLE);
                    final String workTime = CWUtils.getWorkFinishTime(myWork.getEffectiveDate());
                    groupViewHolder.mTimeTv.setText("已结束-" + workTime + "截止");
                    groupViewHolder.mTimeTv.setTextColor(mContext.getResources().getColor(R.color.light_gray16));
                    groupViewHolder.item_my_group_parent_view.setBackgroundColor(mContext.getResources().getColor(R.color.ls_item_option_selected));
                }
                if (isClassWork) {
                    groupViewHolder.iv_my_group_msg.setVisibility(View.VISIBLE);
                    groupViewHolder.iv_my_group_msg.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (null == myWork.getWorkMessage() || "".equals(myWork.getWorkMessage())) {
                                showHomeWorkHintDialog(v, groupViewHolder.iv_my_group_msg, workName, startTime, endTime, workOption, "");
                            } else {
                                showHomeWorkHintDialog(v, groupViewHolder.iv_my_group_msg, workName, startTime, endTime, workOption, workMessage);
                            }

                        }
                    });
                } else if (null != myWork.getWorkMessage() && myWork.getWorkMessage().length() > 0) {
                    groupViewHolder.iv_my_group_msg.setVisibility(View.VISIBLE);
                    groupViewHolder.iv_my_group_msg.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            showHomeWorkHintDialog(v, groupViewHolder.iv_my_group_msg, workName, startTime, endTime, workOption, workMessage);
                        }
                    });
                } else {
                    groupViewHolder.iv_my_group_msg.setVisibility(View.GONE);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
        }
    }

    /**
     * 设置子内容
     *
     * @param groupPosition
     * @param childPosition
     * @param childViewHolder
     */
    private void setChildView(int groupPosition, int childPosition, ChildViewHolder childViewHolder) {
        if (childPosition == 0) {
            childViewHolder.child_diveder.setVisibility(View.GONE);
        } else {
            childViewHolder.child_diveder.setVisibility(View.VISIBLE);
        }
        MyWork myWork = myWorks.get(groupPosition);
        List<WorkContents> workContents = myWork.getWorkContents();
        final WorkContents workContent = workContents.get(childPosition);
        final String resourceName = workContent.getResourceName();
        int moduleId = workContent.getModuleId();
        try {
            if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN ||
                    moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN_NEW) {
                float paddingRight = mContext.getResources().getDimension(R.dimen.dp_15);
                childViewHolder.tv_work_child_name.setPadding(0, 0, (int) paddingRight, 0);
            } else {
                float paddingRight = mContext.getResources().getDimension(R.dimen.dp_3);
                childViewHolder.tv_work_child_name.setPadding(0, 0, (int) paddingRight, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (TextUtils.isEmpty(resourceName)) {
            childViewHolder.tv_work_child_name.setText("");
        } else {
            childViewHolder.tv_work_child_name.setText(resourceName);
            if (workContent.getExamMode() != 0) {
                //模块ID:听说模考 作业类型：0普通作业，1考试作业
                childViewHolder.iv_work_type_kaoshi_icon.setVisibility(View.VISIBLE);
                if (workContent.getExamMode() == 1) {
                    childViewHolder.iv_work_type_kaoshi_icon.setImageResource(R.mipmap.kaoshi_green);
                } else {
                    childViewHolder.iv_work_type_kaoshi_icon.setImageResource(R.mipmap.ceshi_icon);
                }
            } else {
                childViewHolder.iv_work_type_kaoshi_icon.setVisibility(View.GONE);
            }
        }
        if (workContent.getExamMode() == 1 || isClassWork) {
            childViewHolder.tv_total_finish_count.setVisibility(View.GONE);
        } else {
            int totalParent = 0;
            if (workContent.getTotalNum() > 0) {
                totalParent = workContent.getFinishCount() * 100 / workContent.getTotalNum();
            }
            childViewHolder.tv_total_finish_count.setVisibility(View.VISIBLE);
            String workCassFinishCountText = mActivity.getResources().getString(R.string.work_class_finish_count, totalParent + "%");
            childViewHolder.tv_total_finish_count.setText(workCassFinishCountText);
        }
        boolean isSubmit = false;
        if (workType == 1) {
            if (workContent.getErrorWorkId() != null && workContent.getErrorWorkId().length() > 1) {
                isSubmit = true;
            }
        } else {
            if (workContent.getDoWorkId() != null && workContent.getDoWorkId().length() > 1) {
                isSubmit = true;
            }
        }

        if (!(workContent.getSubmitCount() > 0 && isSubmit)) { //未提交过作业。
            childViewHolder.tv_comment.setVisibility(View.GONE);
        } else {
            if (TextUtils.isEmpty(workContent.getCommentContent())) {
                childViewHolder.tv_comment.setVisibility(View.GONE);
            } else {
                childViewHolder.tv_comment.setVisibility(View.VISIBLE);
            }
        }
        childViewHolder.work_btn_area.setVisibility(View.VISIBLE);
        childViewHolder.work_tips_lay.setVisibility(View.GONE);
        if (workContent.getSubmitCount() > 0 && isSubmit) { //提交过作业。
            show_score(childViewHolder, workContent, isSubmit, myWork);//显示分数
            childViewHolder.tv_score_obtain.setOnClickListener(null);
        } else {
            showUnfinishedHomework(childViewHolder, workContent);
        }
        int requireReadTimes = -1;
        String str_requirementContent = workContent.requirementContent;
        if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_REPEAT || moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_SENTENCE_REPEAT
                && !TextUtils.isEmpty(str_requirementContent)) {
            try {
                RequirementContent requirementContent = new Gson().fromJson(str_requirementContent, RequirementContent.class);
                requireReadTimes = requirementContent.getReadtimes();
            } catch (Exception e) {
                e.getStackTrace();
            }
        }

        childViewHolder.tv_work_description.setVisibility(View.GONE);
        childViewHolder.ll_tv_hint_msg.setVisibility(View.GONE);
        childViewHolder.tv_reRead.setVisibility(View.GONE);
        if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_REPEAT ||
                moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_SENTENCE_REPEAT) { //模块ID:同步跟读
            if (workContent.getSubmitCount() >= requireReadTimes) { //跟读达到要求
                childViewHolder.tv_work_description.setVisibility(View.GONE);
            } else {//跟读次数未达到要求
                if (workContent.getSubmitCount() <= 0)//(未达到要求)一次没读时，不用提醒
                    childViewHolder.tv_reRead.setVisibility(View.GONE);
                else
                    childViewHolder.tv_reRead.setVisibility(View.VISIBLE);
                childViewHolder.tv_work_description.setVisibility(View.VISIBLE);
                childViewHolder.tv_work_description.setText("x" + (requireReadTimes - workContent.getSubmitCount()));
            }
            if (!isClassWork) {
                childViewHolder.ll_tv_hint_msg.setVisibility(View.VISIBLE);
                childViewHolder.tv_hint_msg.setText(wordDyeing("老师要求读" + requireReadTimes + "次，", "已读" + workContent.getFeedbackCount() + "次"));
            } else {
                //课堂作业不需要跟读次数
                childViewHolder.ll_tv_hint_msg.setVisibility(View.GONE);
            }
            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.label_gd_normal);
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_DICTATION) { //模块ID:报听写
            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.labe_dictation);
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_LISTEN_SPEAK_EXAM) { //模块ID:听说模考
            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.label_tsmk_normal);
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN ||
                moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN_NEW) { //视频讲解
            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.label_spjj_normal);
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_ONLINE_ANSWER) { //在线作答
            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.label_zxzd_normal);
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_INTERACTIVE_TUTORIAL) { //互动教程
            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.label_hdjc_normal);
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_DUBBING) { //趣味配音
            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.label_spjj_normal);
        } else {
//            childViewHolder.work_btn_area.setVisibility(View.VISIBLE);
//            childViewHolder.iv_work_type_icon.setImageResource(R.mipmap.);
        }
        if (workType == 1) {
            childViewHolder.ll_tv_hint_msg.setVisibility(View.VISIBLE);
            childViewHolder.tv_hint_msg.setText(wordErrorDyeing("错" + workContent.getErrorNum() + "题"));
        }
    }

    private void showRepeatArea(ChildViewHolder childViewHolder) {
        childViewHolder.word_repeat_area.setVisibility(View.VISIBLE);
        childViewHolder.tv_reRead.setVisibility(View.GONE);
    }

    private void showUnfinishedHomework(final ChildViewHolder childViewHolder, final WorkContents workContent) {
        String characterTest = workContent.getShowScore();
        if (characterTest.equals("重做")) {
            if (workContent.getCodeId() == 999) {
                childViewHolder.work_tips_lay.setVisibility(View.VISIBLE);
                childViewHolder.tv_score_obtain.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String tips = "成绩未达标,老师退回";
                        PopWindowUtil.showTipPopupWindowTips(childViewHolder.work_tips_lay, tips, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        });
                    }

                });
                childViewHolder.work_tips_lay.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String tips = "成绩未达标,老师退回";
                        PopWindowUtil.showTipPopupWindowTips(childViewHolder.work_tips_lay, tips, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        });
                    }

                });
            } else if (workContent.getCodeId() == 888) {
                childViewHolder.work_tips_lay.setVisibility(View.VISIBLE);
                childViewHolder.tv_score_obtain.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String tips = "成绩未达标,达标率" + workContent.getAutoRefusePercent() + "%";
                        PopWindowUtil.showTipPopupWindowTips(childViewHolder.work_tips_lay, tips, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        });
                    }

                });
                childViewHolder.work_tips_lay.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String tips = "成绩未达标,达标率" + workContent.getAutoRefusePercent() + "%";
                        PopWindowUtil.showTipPopupWindowTips(childViewHolder.work_tips_lay, tips, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        });
                    }
                });
            } else {
                childViewHolder.work_tips_lay.setVisibility(View.GONE);
            }
        } else {
            childViewHolder.work_tips_lay.setVisibility(View.GONE);
        }
        childViewHolder.word_repeat_area.setVisibility(View.VISIBLE);
        setTextGotScore(childViewHolder.tv_score_obtain, TEXT_SIZE_ZH, mContext.getResources().getColor(R.color.color_AAB2AE), characterTest);
        childViewHolder.tv_total_score.setVisibility(View.GONE);
    }

    /**
     * 作业已完成,未完成(提交过作业)
     *
     * @param childViewHolder
     * @param workContent
     */
    private void show_score(ChildViewHolder childViewHolder, WorkContents workContent, boolean isSubmit, MyWork myWork) {
        //现在时间
        long nowTime = workContent.getNowDate();
        //截止时间
        long effectiveDate = myWork.getEffectiveDate();
        // 查看类型：0 提交立马能查看，1截止时间到后查看
        int seeWorkMode = workContent.getSeeWorkMode();
        //0 提交立马能查看，1截止时间到后查看
        int showScoreMode = workContent.getShowScoreMode();
        float workScore = workContent.getWorkScore();
        //显示的分数（服务器判断是否显示）
        String showScore = workContent.getShowScore();
        int moduleId = workContent.getModuleId();
        int workStatus = workContent.getWorkStatus();
        if (workType == 1) {
            workScore = workContent.getErrorWorkScore();
        }
        String totalScore = subZeroAndDot(workScore + "");
        //互动教程 单独定义规则（为了区分有题与无题）：totalScore为零分时代表没题，有题分值一定大于零（因为每个小题赋值一分）
        if (moduleId != ModuleInfo.ModuleInfoId.MODULE_ID_INTERACTIVE_TUTORIAL) {
            if (totalScore.equals("0") || totalScore.equals("0.00") || totalScore.equals("0.00")) {
                totalScore = "100";
            }
            totalScore = totalScore + "分";
        }
        childViewHolder.tv_score_obtain.setTextSize(TEXT_SIZE_EN);
        childViewHolder.tv_score_obtain.setTextColor(mContext.getResources().getColor(R.color.color_light_green));
        childViewHolder.tv_total_score.setVisibility(View.VISIBLE);
        childViewHolder.ll_tv_hint_msg.setVisibility(View.GONE);
        if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_REPEAT ||//同步跟读(老资源 单词 句子)
                moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_SENTENCE_REPEAT ||//新资源 句子
                moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_DUBBING ||//新资源 句子
                moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_DICTATION) { // 待批改 已批改 作业提交成功 得分/总分
            showRepeatArea(childViewHolder);
            childViewHolder.tv_total_score.setText(totalScore);
            if (workStatus != EpaperConstant.SCORE_STATUS_UNCOMPLETE) {
                childViewHolder.tv_score_obtain.setText(showScore);
            }
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_LISTEN_SPEAK_EXAM) {//听说模考
            showRepeatArea(childViewHolder);
            childViewHolder.tv_total_score.setText(totalScore);
            if (workStatus != EpaperConstant.SCORE_STATUS_UNCOMPLETE
                    && workStatus != EpaperConstant.SCORE_STATUS_TSMK_UNCOMPLETE) {
                childViewHolder.tv_score_obtain.setText(showScore);
            } else if (workStatus == EpaperConstant.SCORE_STATUS_UNCOMPLETE) {
                setTextGotScore(childViewHolder.tv_score_obtain, TEXT_SIZE_ZH, mContext.getResources().getColor(R.color.color_light_green), "评分中");
            } else if (workStatus == EpaperConstant.SCORE_STATUS_TSMK_UNCOMPLETE) {
                setTextGotScore(childViewHolder.tv_score_obtain, TEXT_SIZE_ZH, mContext.getResources().getColor(R.color.color_light_green), "批改中");
            }
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_ONLINE_ANSWER) {//在线作答
            showRepeatArea(childViewHolder);
            childViewHolder.tv_total_score.setText(totalScore);
            if (workStatus != EpaperConstant.SCORE_STATUS_UNCOMPLETE
                    && workStatus != EpaperConstant.SCORE_STATUS_TSMK_UNCOMPLETE
                    && workStatus != EpaperConstant.SCORE_STATUS_ONLINEANSWER_UNCOMPLETE) {
                childViewHolder.tv_score_obtain.setText(showScore);
            } else if (workStatus == EpaperConstant.SCORE_STATUS_TSMK_UNCOMPLETE
                    || workStatus == EpaperConstant.SCORE_STATUS_ONLINEANSWER_UNCOMPLETE) {
                setTextGotScore(childViewHolder.tv_score_obtain, TEXT_SIZE_ZH, mContext.getResources().getColor(R.color.color_light_green), "批改中");
            }
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN ||
                moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN_NEW) { //视频讲解
            childViewHolder.work_btn_area.setVisibility(View.GONE);
        } else if (moduleId == ModuleInfo.ModuleInfoId.MODULE_ID_INTERACTIVE_TUTORIAL) { //互动教程
            if (isSubmit && Long.valueOf(totalScore) > 0) {
                totalScore = totalScore + "分";
                childViewHolder.tv_total_score.setText(totalScore);
                childViewHolder.tv_score_obtain.setText(showScore);
            } else {//当互动教程没题（及没有总分数）、视频讲解
                childViewHolder.work_btn_area.setVisibility(View.GONE);
            }
        } else {
            showRepeatArea(childViewHolder);
        }
    }

    /**
     * 设置获取分数或者文字，以及对应的颜色，大小
     */
    private void setTextGotScore(TextView textView, int size, int colorRes, CharSequence character) {
        textView.setTextSize(size);
        textView.setTextColor(colorRes);
        textView.setText(character);
    }

    /**
     * 拼接带颜色数字，文字
     *
     * @param beforText
     * @param afterText
     * @return
     */
    public CharSequence wordDyeing(String beforText, String afterText) {
        ForegroundColorSpan colorSpanBefor = new ForegroundColorSpan(Color.parseColor("#F67177"));
        ForegroundColorSpan colorSpanAfter = new ForegroundColorSpan(Color.parseColor("#52CC8F"));
        SpannableStringBuilder spannableString = new SpannableStringBuilder(beforText);
        spannableString.setSpan(colorSpanBefor, beforText.indexOf("次") - 1, beforText.indexOf("次"), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spannableString.append(afterText);
        spannableString.setSpan(colorSpanAfter, spannableString.length() - 2, spannableString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    /**
     * 拼接带颜色数字，文字
     *
     * @param beforText
     * @return
     */
    public CharSequence wordErrorDyeing(String beforText) {
        ForegroundColorSpan colorSpanBefor = new ForegroundColorSpan(Color.parseColor("#F67177"));
        SpannableStringBuilder spannableString = new SpannableStringBuilder(beforText);
        spannableString.setSpan(colorSpanBefor, 0, beforText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    /**
     * 使用java正则表达式去掉小数点多余的.与0
     *
     * @param s
     * @return
     */
    private static String subZeroAndDot(String s) {
        if (s.indexOf(".") > 0) {
            s = s.replaceAll("0+?$", "");//去掉多余的0
            s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
        }
        return s;
    }

    /**
     * 显示作业布置信息
     *
     * @param clickView
     * @param iv_my_group_msg
     * @param workName
     * @param endTime
     * @param workMessage
     */
    private void showHomeWorkHintDialog(View clickView, ImageView iv_my_group_msg, String workName, String startTime, String endTime, String workOption, String workMessage) {

        View workHintDialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_home_work_hint, null);
        final int spotXY[] = new int[2];
        // 获取锚点View在屏幕上的左上角坐标位置
        iv_my_group_msg.getLocationOnScreen(spotXY);
        int spotX = iv_my_group_msg.getWidth();
        int spotY = iv_my_group_msg.getHeight();
        //偏移量 = 屏幕的一半 - 弹窗的一半 - 锚点的一半 - 边距
        int screenWidth = DisplayUtils.getScreenWidth(mContext);
        int screenHeight = DisplayUtils.getScreenHeight(mContext);
        workHintDialogView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int dialogWidth = workHintDialogView.getMeasuredWidth();
        int dialogHeight = workHintDialogView.getMeasuredHeight();
        int offsetX = (screenWidth / 2 - dialogWidth / 2 - (screenWidth - spotXY[0]) + spotX / 2);//右边便宜要加上锚点的一半和右边的边距。
        int offsetY = -(screenHeight / 2 - dialogHeight / 2 - spotXY[1] + DisplayUtils.getStatusBarHeight(mContext) / 2 - spotY) + DisplayUtils.dip2px(mContext, 35);
        CWLog.i("offsetX", +offsetX + "");
        CWLog.i("offsetY", +offsetY + "");
        final HomeWorkHintDialog homeWorkHintDialog = new HomeWorkHintDialog(mContext, workHintDialogView, workName,
                startTime, endTime, workOption, workMessage, offsetX, offsetY, true);
        homeWorkHintDialog.show();
        workHintDialogView.findViewById(R.id.rll_group_head).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                homeWorkHintDialog.dismiss();
            }
        });
    }

    /**
     * 组视图助手
     */
    private class GroupViewHolder {
        /**
         * 时间
         */
        private TextView mTimeTv;
        /**
         * 进行中
         */
        private ImageView iv_my_work_status_start;
        /**
         * 已结束
         */
        private ImageView iv_my_work_status_finish;
        /**
         * 整个item view句柄,用于当作业撤销时隐藏整个item
         */
        private View item_my_group_parent_view;

        /**
         * 留言按钮
         */
        private ImageView iv_my_group_msg;
    }

    /**
     * 子视图助手
     */
    public static class ChildViewHolder {
        /**
         * 作业内容名称
         */
        public TextView tv_work_child_name;
        View child_diveder;
        /**
         * 跟读模式
         */
        public TextView tv_work_description, tv_hint_msg, tv_reRead;
        public TextView tv_score_obtain;
        /**
         * 总分数
         */
        public TextView tv_total_score;
        /**
         * 作业类型
         */
        public ImageView iv_work_type_icon, iv_work_type_kaoshi_icon;
        public TextView tv_comment;

        /**
         * 点击区域
         */
        public ViewGroup work_btn_area;
        /**
         * 跟读次数文字容器
         */
        public ViewGroup ll_tv_hint_msg;

        public ViewGroup word_repeat_area;

        public ImageView work_tips_lay;

        /**
         * 班级作业完成进度
         */
        public TextView tv_total_finish_count;
    }

}
